package com.ruoyi.registration.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.registration.domain.Registration;
import com.ruoyi.registration.service.IRegistrationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报名信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-23
 */
@RestController
@RequestMapping("/registration/registration")
public class RegistrationController extends BaseController
{
    @Autowired
    private IRegistrationService registrationService;

    /**
     * 查询报名信息列表
     */
    @PreAuthorize("@ss.hasPermi('registration:registration:list')")
    @GetMapping("/list")
    public TableDataInfo list(Registration registration)
    {
        startPage();
        List<Registration> list = registrationService.selectRegistrationList(registration);
        return getDataTable(list);
    }
    /**
     *查询已缴费的报名信息
     */
    @PreAuthorize("@ss.hasPermi('registration:registration:listPayed')")
    @GetMapping("/listPayed")
    public TableDataInfo listPayed(Registration registration)
    {
        startPage();
        List<Registration> list = registrationService.selectRegistrationList(registration);
        return getDataTable(list);
    }
    /**
     * 导出报名信息列表
     */
    @PreAuthorize("@ss.hasPermi('registration:registration:export')")
    @Log(title = "报名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Registration registration)
    {
        List<Registration> list = registrationService.selectRegistrationList(registration);
        ExcelUtil<Registration> util = new ExcelUtil<Registration>(Registration.class);
        util.exportExcel(response, list, "报名信息数据");
    }

    /**
     * 获取报名信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('registration:registration:query')")
    @GetMapping(value = "/{regisId}")
    public AjaxResult getInfo(@PathVariable("regisId") Long regisId)
    {
        return success(registrationService.selectRegistrationByRegisId(regisId));
    }

    /**
     * 新增报名信息
     */
    @PreAuthorize("@ss.hasPermi('registration:registration:add')")
    @Log(title = "报名信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Registration registration)
    {
        return toAjax(registrationService.insertRegistration(registration));
    }

    /**
     * 修改报名信息
     */
    @PreAuthorize("@ss.hasPermi('registration:registration:edit')")
    @Log(title = "报名信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Registration registration)
    {
        return toAjax(registrationService.updateRegistration(registration));
    }

    /**
     * 删除报名信息
     */
    @PreAuthorize("@ss.hasPermi('registration:registration:remove')")
    @Log(title = "报名信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{regisIds}")
    public AjaxResult remove(@PathVariable Long[] regisIds)
    {
        return toAjax(registrationService.deleteRegistrationByRegisIds(regisIds));
    }

    @PreAuthorize("@ss.hasPermi('registration:registration:query')")
    @GetMapping()
    public AjaxResult getRegistrationFees()
    {
        return success(registrationService.selectRegistrationNofeesByregisId());
    }
}
